package com.songcha.library_business.helper

import android.content.Context
import android.graphics.Color
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshFooter
import com.scwang.smart.refresh.layout.api.RefreshHeader
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator
import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator

class SmartRefreshHelper {
    companion object{
        @JvmStatic
        fun init(){
            SmartRefreshLayout.setDefaultRefreshHeaderCreator(object: DefaultRefreshHeaderCreator {
                override fun createRefreshHeader(context: Context, layout: RefreshLayout): RefreshHeader {
                    layout.setPrimaryColorsId(com.songcha.library_common.R.color.primary, com.songcha.library_common.R.color.white)//全局设置主题颜色
                    return MaterialHeader(context).apply {
                        setColorSchemeResources(com.songcha.library_common.R.color.primary,
                            com.songcha.library_common.R.color.primary)
                    }
                    //return CustomRefreshHeader(context)
                }
            })
            //set global footer builder
            SmartRefreshLayout.setDefaultRefreshFooterCreator(object: DefaultRefreshFooterCreator {
                override fun createRefreshFooter(context: Context, layout: RefreshLayout): RefreshFooter {
                    //set to classic footer,default is BallPulseFooter
                    //val footer=ClassicsFooter(context).setDrawableSize(20f)
                    //footer.setBackgroundColor(ColorUtil.getResourceColor(context,R.color.background))
                    //return footer
                    return ClassicsFooter(context).setDrawableSize(20f).apply {
                        setBackgroundColor(Color.TRANSPARENT)
                    }
                }

            })
        }
    }
}